package main

import (
	"fmt"
	"net/rpc"
)

type AddGoodsReq struct {
	Id      int
	Title   string
	Price   float32
	Content string
}

type AddGoodsRes struct {
	Success bool
	Message string
}

func main() {
	// 1.用rpc.Dial和rpc微服务端建立连接
	conn, err := rpc.Dial("tcp", "127.0.0.1:9001")
	if err != nil {
		fmt.Println(err)
		return
	}

	// 2.客户端退出关闭连接
	defer conn.Close()

	// 3.调用远程函数
	var reply AddGoodsRes
	err = conn.Call("goods.AddGoods", AddGoodsReq{
		Id:      1,
		Title:   "测试",
		Price:   100,
		Content: "详情",
	}, &reply)
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println(reply)

}
